package com.haier.npt.config;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Component;

import springfox.documentation.swagger.web.SwaggerResource;
import springfox.documentation.swagger.web.SwaggerResourcesProvider;

/**
 * @Description:swagger配置文件 
 * @author: lixu
 * @date:   2018年7月20日 下午3:28:46   
 */
@Component
@Primary
public class DocumentationConfig implements SwaggerResourcesProvider{
	
	@Value("${swagger.info.doc-module}")
	private String docModule;
	
	@Override
    public List<SwaggerResource> get() {
		String[] docModules = null;
		List<SwaggerResource> resources = new ArrayList<>();
		if(StringUtils.isNotEmpty(docModule)){
			docModules = docModule.split(",");
			for(String item:docModules){
				String[] itemArray = item.split(":");
		        resources.add(swaggerResource(itemArray[0], itemArray[1], itemArray[2]));
			}
		}
        return resources;
    }

    private SwaggerResource swaggerResource(String name, String location, String version) {
        SwaggerResource swaggerResource = new SwaggerResource();
        swaggerResource.setName(name);
        swaggerResource.setLocation(location);
        swaggerResource.setSwaggerVersion(version);
        return swaggerResource;
    }
}
